package com.hunlian.makelove.dialog;

import android.app.Activity;
import android.app.AlertDialog;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.hunlian.makelove.R;

/**
 * Created by zealjiang on 2017/5/15 16:22.
 * Email: zealjiang@126.com
 */

public class EduDialog {

    /**
     * 这是兼容的 AlertDialog 带取消和确定按钮
     * @author zealjiang
     * @time 2016/8/11 11:31
     */
    public void showDialog(Activity activity,String content, AgreeBtnInf agreeBtnInf) {

        mAgreeBtnInf = agreeBtnInf;
        final AlertDialog dialog = new AlertDialog.Builder(activity).create();
        dialog.setCancelable(false);
        dialog.setCanceledOnTouchOutside(false);

        View view = LayoutInflater.from(activity).inflate(
                R.layout.dialog_accept_refuse, null);
        dialog.setView(view);
        try {
            dialog.show();
        } catch (Exception e) {
        }

        DisplayMetrics dm = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
        WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
        lp.width = (int) (dm.widthPixels * 0.86); // 设置宽度
        Window window = dialog.getWindow();
        window.setContentView(R.layout.dialog_accept_refuse);
        window.setAttributes(lp);

        TextView tvContent = (TextView) window.findViewById(R.id.content);
        tvContent.setText(content);

        Button btnAgree = (Button) window.findViewById(R.id.btn_agree);
        btnAgree.setText("上传学历");
        Button btnCancel = (Button) window.findViewById(R.id.btn_cancel);

        btnAgree.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if(mAgreeBtnInf!=null){
                    mAgreeBtnInf.ok();
                }
            }
        });

        btnCancel.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
    }

    public AgreeBtnInf mAgreeBtnInf;
    public interface AgreeBtnInf{
        void ok();
    }
}
